import { sys } from "cc";
import SdkTool from "../Sdk/SdkTool";
import Instance from "./Instance";
import Log from "../Log/Log";

export class LocalUtil {
    public static get ins(): LocalUtil {
        return Instance.get(LocalUtil);
    }
    private formatName(name: string): string {
        return SdkTool.ins.openid + `_` + name;
    }
    /**
     * 清除所有
     */
    public clearAll(): void {
        sys.localStorage.clear();
    }

    /**
     * 获取Cookie
     */
    public getCookie(name: string): any {
        return sys.localStorage.getItem(this.formatName(name));
    }

    /**
     * 设置私Cookie
     */
    public setCookie(name: string, value: any): void {
        const key = this.formatName(name)
        sys.localStorage.setItem(key, value);
        Log.ins.log(1, `数据已保存到本地：key:${key},value:${value}`);
    }
}